from django.db import models
from django.utils.timezone import now
from app.account.models import UserInfo
from app.outdoor.models import Activity


# Create your models here.


class LoginLog(models.Model):
    """登录日志记录"""

    device = {
        ('android', '安卓'),
        ('apple', '苹果'),
        ('web', '网页'),
        ('weapp', '微信小程序')
    }

    '''记录用户登录信息'''
    ip = models.CharField(verbose_name='用户ip', max_length=200, blank=False, default='')

    user = models.ForeignKey(UserInfo, verbose_name='关联用户', on_delete=models.CASCADE, blank=False, default='')

    login_device = models.CharField(verbose_name='登录端', blank=False, default='web', choices=device, max_length=100)

    loginTime = models.DateTimeField(verbose_name='登录时间', default=now)

    def __str__(self):
        return str(self.ip)

    class Meta:
        verbose_name = '登录日志记录'
        verbose_name_plural = verbose_name + '列表'
        db_table = 'log_LoginLog'
        ordering = ['-loginTime']


class ActivityChangeLog(models.Model):
    """活动变化历史表"""
    related_activity = models.ForeignKey(Activity, verbose_name='关联活动', on_delete=models.CASCADE, blank=False,
                                         default='')
    related_user = models.ForeignKey(UserInfo, verbose_name='关联用户', on_delete=models.CASCADE, blank=False, default='')

    action = models.CharField(verbose_name='动作', default='', blank=False, max_length=100)

    from django.utils.timezone import now
    mod_time = models.DateTimeField(verbose_name='修改时间', default=now)

    class Meta:
        verbose_name = '活动变化历史'
        verbose_name_plural = verbose_name + '列表'
        db_table = 'log_ActivityChangeLog'
        ordering = ['-mod_time']

    def __str__(self):
        return self.related_activity
